package progetto1.csm.implementation;

import java.util.HashMap;
import java.util.Map;

import progetto1.csm.core.AbstractStatistics;
import progetto1.csm.core.StatisticType;
import progetto1.csm.core.SystemElement;

public class CSMStatistics extends AbstractStatistics {
	
	private Map<Couple<StatisticType,SystemElement>, Double> statistics = new HashMap<Couple<StatisticType,SystemElement>, Double>();
	private int nClient;
	
	protected CSMStatistics(){
	}
	
	protected CSMStatistics(int numClient) {
		this.nClient=numClient;
	}
	
	@Override
	protected void addStatistic(StatisticType st, SystemElement se, double value) {
		statistics.put(new Couple<StatisticType,SystemElement>(st,se), new Double(value));
	}
	
	@Override
	protected void clear(){
		statistics.clear();
	}

	@Override
	protected void setNClient(int nClient) {
		this.nClient = nClient;
		clear();
	}
	
	@Override
	public double getValue(StatisticType st, SystemElement se) {
		return statistics.get(new Couple<StatisticType,SystemElement>(st,se)).doubleValue();//evitiamo l'autoboxing
	}

	@Override
	public int getNumClient() {
		return nClient;
	}

	@Override
	public SystemElement[] getSystemElements() {
		return CSMSystemElements.values();
	}

	@Override
	public StatisticType[] getStatisticsTypes() {
		return CSMStatisticsTypes.values();
	}
	
	@Override
	public String toString() {
		return "CSMStatistics [statistics=" + statistics + ", nClient="
				+ nClient + "]";
	}
}
